home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / amigagadget / ausgabe13 / texte / prg.non_rectangular_images < prev    next >
Text File  |  1995-02-23  |  3KB  |  79 lines

  1. #Titel DrawImage & non-rectangular Image
  2. #Logo pinsel/ag.prog
  3. #C32
  4.  
  5. #Font Frankfurter 16
  6. DrawImage & non-rectangular Image
  7. #Font topaz 8
  8. #C21
  9.  
  10. People  frequently ask how to use DrawImage to put a non-rectangular Image into
  11. a  RastPort.  The  answer  is  "You  can't".  There is, of course, a way to put
  12. non-rectangular  image  data  into  a  RastPort  which  is  only  slightly more
  13. difficult  than  using  DrawImage. Instead of storing your data as an Image you
  14. must  store  it  as  a  BitMap.  This  is  because you must draw the image with
  15. BltMaskBitMapRastPort.  The  method  for  drawing  an  image  with an arbitrary
  16. transparent color into a RastPort is explained below:
  17.  
  18. For  a  BitMap,  the  actual image data is stored the same as for an Image. The
  19. BitMap  structure  is  constructed  like this (Assuming the image data is in an
  20. array called "Buffer"):
  21.  
  22. #C10
  23.   PlaneBytes = RASSIZE(ImageWidth, ImageHeight);
  24.   BM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR);
  25.   InitBitMap(BM, ImageDepth, ImageWidth, ImageHeight);
  26.   for (i = 0; i < ImageDepth; i++)
  27.     BM->Planes[i] = &Buffer[PlaneBytes * i];
  28. #C21
  29.  
  30. The  construction  of  the  mask is the next step. The Mask is just a bit plane
  31. with  the  same dimensions as the image bitplanes. The blitter routines require
  32. the  use  of BitMaps so we construct two temporary BitMap structures. MaskBM is
  33. the  BitMap  for the Mask. TempBM is the BitMap which will contain successively
  34. each  plane  of  the  image  data.  The  third  from  the last parameter in the
  35. BltBitMap  calls  is  the  "minterm".  0xb0 causes BltBitMap to set all bits in
  36. MaskBM  which  are  not  set  in  TempBM  (In  addition to those already set in
  37. MaskBM).  0xe0  causes  BltBitMap  to  set  all bits in MaskBM which are set in
  38. TempBM (In addition to those already set in MaskBM).
  39.  
  40. #C10
  41.   Mask = AllocRaster(ImageWidth, ImageHeight);
  42.   BltClear(Mask, PlaneBytes, 1);
  43.   MaskBM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR));
  44.   InitBitMap(MaskBM, 1, ImageWidth, ImageHeight);
  45.   MaskBM->Planes[0] = Mask;
  46.   TempBM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR));
  47.   InitBitMap(TempBM, 1, ImageWidth, ImageHeight);
  48.   for (i = 0; i < ImageDepth; i++)
  49.   {
  50.     TempBM->Planes[0] = &Buffer[PlaneBytes * i];
  51.     if (TransparentColor & (1<<i))
  52.       BltBitMap(TempBM, 0, 0, MaskBM, 0, 0, ImageWidth, ImageHeight, 0xb0,
  53.                 0xff, NULL);
  54.     else
  55.       BltBitMap(TempBM, 0, 0, MaskBM, 0, 0, ImageWidth, ImageHeight, 0xe0,
  56.                 0xff, NULL);
  57.   }
  58.   FreeMem(TempBM, sizeof(struct BitMap));
  59.   FreeMem(MaskBM, sizeof(struct BitMap));
  60. #C21
  61.  
  62. This  code allows for a general transparent color which need not be color zero.
  63. The "if" statement could be removed if the transparent color was always 0.
  64. #Seitenende
  65. To  place  this image at a point "X, Y" in the window "Window" you only need to
  66. make the following call.
  67.  
  68. #C10
  69.   BltMaskBitMapRastPort(BM, 0, 0, Window->RPort, X, Y, ImageWidth,
  70.                         ImageHeight, 0xe0, Mask);
  71. #C21
  72.  
  73. There!  Now,  wasn't  that simple. Of course, in any real program it would be a
  74. good idea to check the return values of all routines which allocate memory.
  75.  
  76. #C31
  77.                                                                   by Mike Stark
  78. #C21
  79.